﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using NLite.Persistence;

namespace NLite.NHPersistenceTest
{
    [TestFixture]
    public class RepositoryTest:TestBase
    {
       

        [Test]
        public void test_SaveOrUpdate()
        {
            UserInfo user=new UserInfo()
            {
                 Name="TestName",
                 Age=100
            };
            repository.SaveOrUpdate(user);

            var user2 = query.FirstOrDefault(p => p.Id == user.Id);
            Assert.AreEqual(user, user2);

            user.Name = "TestName2";
            repository.SaveOrUpdate(user);

            user2 = query.FirstOrDefault(p => p.Id == user.Id);
            Assert.AreEqual(user2.Name, "TestName2");
            repository.Delete(user.Id);
        }

        [Test]
        public void test_Delete()
        {
            UserInfo user = new UserInfo()
            {
                Name = "Delete_test",
                Age = 110
            };
            repository.SaveOrUpdate(user);

            var user2 = query.FirstOrDefault(p => p.Id == user.Id);
            Assert.AreEqual(user, user2);
            repository.Delete(user.Id);

            user2 = query.FirstOrDefault(p => p.Id == user.Id);
            Assert.Null(user2);
        }


    }
}
